package com.tjs.lucky.domain.strategy.service.draw.impl;

import cn.hutool.json.JSON;
import cn.hutool.json.JSONUtil;
import com.tjs.lucky.domain.strategy.service.algo.IDrawAlgorithm;
import com.tjs.lucky.domain.strategy.service.draw.AbstractDrawBase;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author: 田佳澍
 * @Description:
 * @DateTime: 2023/5/16 14:31
 **/
@Service("drawExec")
public class DrawExecImpl extends AbstractDrawBase {

    private final Logger logger = LoggerFactory.getLogger(DrawExecImpl.class);

    @Override
    protected List<String> queryExcludeAwardIds(Long strategyId) {
        List<String> awardList = strategyRepository.queryNoStockStrategyAwardList(strategyId);
        logger.info("执行抽奖策略 strategyId：{}，无库存排除奖品列表ID集合 awardList：{}", strategyId, JSONUtil.toJsonStr(awardList));
        return awardList;
    }

    @Override
    protected String drawAlgorithm(Long strategyId, IDrawAlgorithm drawAlgorithm, List<String> excludeAwardIds) {
        // 执行抽奖
        return drawAlgorithm.randomDraw(strategyId, excludeAwardIds);
    }

}
